﻿using System;
using System.Collections.Generic;
using BruteForce.Animation;
using BruteForce.GameObjects;
using BruteForce.NewManagers;
using BruteForce.Screens.PlayingScreen.Map;
using BruteForce.Screens.PlayingScreen.Panels;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BruteForce.Characters
{
    public class Bomber : Character
    {


        private ExplosionTransition explosionTransition;
        private ExplosionTransition beenHitTransition;

        public Bomber(Resources initialResource, bool human, GamePanel gamePanel, Vector2 initialPosition, MapCell mapCell, PlayerType player)
            : base(gamePanel, initialResource, initialPosition,mapCell, player)
        {
            IsHuman = human;
            AnimationTransition = new LinearFrameAnimationTransition(0,
                                                                     VisualMap[
                                                                         new Key((human ? "Humans" : "Monsters"),
                                                                                 "Bomber", "walking", "se")], 0.025);
            Type = CharacterType.Bomber;
            explosionTransition = new ExplosionTransition(1, new List<Texture2D>(), 0.0005, Vector2.Zero);
            explosionTransition.OnTransitionDone += ExplodingOnTransitionDone;
            beenHitTransition = new ExplosionTransition(1, new List<Texture2D>(), 0.0005, Vector2.Zero);
            beenHitTransition.OnTransitionDone += BeenHitOnTransitionDone;
        }

        

        public override void BeenShot(Vector2 startPos) {
            beenHitTransition.TextureSwitchDuration = 0.0625;
            beenHitTransition.Position = WalkingTransition.CurrentPosition;
            beenHitTransition.StartTransition();
            beenHitTransition.Duration = 1;
            DecreaseLife(InitialResources.Life);
            
//            PlayerManager.Instance.Explode(this);
        }

        public void Explode()
        {
            explosionTransition.TextureSwitchDuration = 0.0625;
            explosionTransition.Position = WalkingTransition.CurrentPosition;
            explosionTransition.StartTransition();
            explosionTransition.Duration = 1;

            DecreaseLife(InitialResources.Life);

//            InitialResources.Life = 0;

//            GamePanel.Current.RemoveCharacter(this);

//            if (BelongsToPlayer == PlayerType.Human)
//                GamePanel.Current.HumanPlayer.RemoveGamePiece(this);
//            else
//                GamePanel.Current.MonsterPlayer.RemoveGamePiece(this);

//            PlayerManager.Instance.Explode(this);
        }

        private void ExplodingOnTransitionDone()
        {
            GamePanel.Current.AfterShooting(explosionTransition.Position);
        }

        private void BeenHitOnTransitionDone() {
            GamePanel.Current.AfterBomberBeenHit(this, beenHitTransition.Position);
        }


    }
}